﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Media;
using Spinning.Spinning.Unitity;

namespace Spinning.Spinning
{
    public static class MusicManager
    {
        static Dictionary<string, Music> _musicTable = new Dictionary<string, Music>();

        static String preId = "";

        public static void AddMusic(String fromUrl, String id, float interval, bool looped) 
        {
            Music nextToAdd = new Music(fromUrl, interval, looped);
            _musicTable.Add(id, nextToAdd);
        }

        public static void PlayMusic(String id)
        {
            if (id != preId)
            {
                if(preId != "")_musicTable[preId].MusicStop();
                _musicTable[id].MusicPlay();
            }
            preId = id;
        }

        public static void PauseMusic(String id)
        {
            _musicTable[id].MusicPause();
        }

        public static void StopMusic(String id)
        {
            _musicTable[id].MusicStop();

        }

        public static void SetRePlay(bool set, String id)
        {
            _musicTable[id].Repeat = set;

        }

        public static void FreeAllMusic()
        {
            foreach (Music m in _musicTable.Values)
            {
                m.MusicFree();
            }
            _musicTable.Clear();
        }

        public static void SetVolume(string id, float volume)
        {
            _musicTable[id].Volume = volume;

        }
    }
}
